#include "StompedReality/Asset/PatchSystem.h"
#include <UnitTest++.h>
SUITE( Texture_System_Test )
{
  // Quad strip
  // left bottom
  // right bottom
  // left top
  // right top
  TEST( PATCH_BUFFER_CREATION_SIMPLE_VPOS )
  {
    StompedReality::Asset::PatchSystem system;
    float* bufferSimple = system.CalculateBufferRect( 100, 200 );
    CHECK_CLOSE( -50.0f, bufferSimple[0], 0.001f );
    CHECK_CLOSE( 100.0f, bufferSimple[1], 0.001f );
    CHECK_CLOSE( 50.0f, bufferSimple[4], 0.001f );
    CHECK_CLOSE( 100.0f, bufferSimple[5], 0.001f );
    CHECK_CLOSE( -50.0f, bufferSimple[8], 0.001f );
    CHECK_CLOSE( -100.0f, bufferSimple[9], 0.001f );
    CHECK_CLOSE( 50.0f, bufferSimple[12], 0.001f );
    CHECK_CLOSE( -100.0f, bufferSimple[13], 0.001f );
    delete[] bufferSimple;
  }
  TEST( PATCH_BUFFER_CREATION_SIMPLE_UV )
  {
    StompedReality::Asset::PatchSystem system;
    float* bufferSimple = system.CalculateBufferRect( 100, 200 );
    system.UpdateUV( bufferSimple, 100, 200, 0, 0, 100, 200 );
    CHECK_CLOSE( 0.0f, bufferSimple[2], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[3], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[6], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[7], 0.001f );
    CHECK_CLOSE( 0.0f, bufferSimple[10], 0.001f );
    CHECK_CLOSE( 0.0f, bufferSimple[11], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[14], 0.001f );
    CHECK_CLOSE( 0.0f, bufferSimple[15], 0.001f );
    delete[] bufferSimple;
  }

  TEST( PATCH_BUFFER_CREATION_TLQUAD_UV )
  {
    StompedReality::Asset::PatchSystem system;
    float* bufferSimple = system.CalculateBufferRect( 100, 200 );
    system.UpdateUV( bufferSimple, 100, 200, 0, 0, 50, 100 );
    CHECK_CLOSE( 0.0f, bufferSimple[2], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[3], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[6], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[7], 0.001f );
    CHECK_CLOSE( 0.0f, bufferSimple[10], 0.001f );
    CHECK_CLOSE( 0.0f, bufferSimple[11], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[14], 0.001f );
    CHECK_CLOSE( 0.0f, bufferSimple[15], 0.001f );
    delete[] bufferSimple;
  }
  TEST( PATCH_BUFFER_CREATION_TRQUAD_UV )
  {
    StompedReality::Asset::PatchSystem system;
    float* bufferSimple = system.CalculateBufferRect( 50, 100 );
    system.UpdateUV( bufferSimple, 100, 200, 50, 0, 50, 100 );
    CHECK_CLOSE( 0.5f, bufferSimple[2], 0.001f ); // BL x
    CHECK_CLOSE( 0.5f, bufferSimple[3], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[6], 0.001f ); // Br x
    CHECK_CLOSE( 0.5f, bufferSimple[7], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[10], 0.001f ); // TL x
    CHECK_CLOSE( 0.0f, bufferSimple[11], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[14], 0.001f ); // TR x
    CHECK_CLOSE( 0.0f, bufferSimple[15], 0.001f );
    delete[] bufferSimple;
  }
  TEST( PATCH_BUFFER_CREATION_BLQUAD_UV )
  {
    StompedReality::Asset::PatchSystem system;
    float* bufferSimple = system.CalculateBufferRect( 50, 100 );
    system.UpdateUV( bufferSimple, 100, 200, 0, 100, 50, 100 );
    CHECK_CLOSE( 0.0f, bufferSimple[2], 0.001f ); // BL x
    CHECK_CLOSE( 1.0f, bufferSimple[3], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[6], 0.001f ); // Br x
    CHECK_CLOSE( 1.0f, bufferSimple[7], 0.001f );
    CHECK_CLOSE( 0.0f, bufferSimple[10], 0.001f ); // TL x
    CHECK_CLOSE( 0.5f, bufferSimple[11], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[14], 0.001f ); // TR x
    CHECK_CLOSE( 0.5f, bufferSimple[15], 0.001f );
    delete[] bufferSimple;
  }
  TEST( PATCH_BUFFER_CREATION_BRQUAD_UV )
  {
    StompedReality::Asset::PatchSystem system;
    float* bufferSimple = system.CalculateBufferRect( 50, 100 );
    system.UpdateUV( bufferSimple, 100, 200, 50, 100, 50, 100 );
    CHECK_CLOSE( 0.5f, bufferSimple[2], 0.001f ); // BL x
    CHECK_CLOSE( 1.0f, bufferSimple[3], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[6], 0.001f ); // Br x
    CHECK_CLOSE( 1.0f, bufferSimple[7], 0.001f );
    CHECK_CLOSE( 0.5f, bufferSimple[10], 0.001f ); // TL x
    CHECK_CLOSE( 0.5f, bufferSimple[11], 0.001f );
    CHECK_CLOSE( 1.0f, bufferSimple[14], 0.001f ); // TR x
    CHECK_CLOSE( 0.5f, bufferSimple[15], 0.001f );
    delete[] bufferSimple;
  }
  TEST( PATCH_BUFFER_CREATION_CQUAD_UV )
  {
    StompedReality::Asset::PatchSystem system;
    float* bufferSimple = system.CalculateBufferRect( 50, 100 );
    system.UpdateUV( bufferSimple, 100, 200, 25, 50, 50, 100 );
    CHECK_CLOSE( 0.25f, bufferSimple[2], 0.001f ); // BL x
    CHECK_CLOSE( 0.75f, bufferSimple[3], 0.001f );
    CHECK_CLOSE( 0.75f, bufferSimple[6], 0.001f ); // Br x
    CHECK_CLOSE( 0.75f, bufferSimple[7], 0.001f );
    CHECK_CLOSE( 0.25f, bufferSimple[10], 0.001f ); // TL x
    CHECK_CLOSE( 0.25f, bufferSimple[11], 0.001f );
    CHECK_CLOSE( 0.75f, bufferSimple[14], 0.001f ); // TR x
    CHECK_CLOSE( 0.25f, bufferSimple[15], 0.001f );
    delete[] bufferSimple;
  }
}
